use std::sync::Arc;

use axum::{async_trait, extract::FromRequestParts, http::request::Parts};

use crate::AppState;

pub struct Auth(pub String);

#[async_trait]
impl FromRequestParts<Arc<AppState>> for Auth {
    type Rejection = &'static str;

    async fn from_request_parts(
        _parts: &mut Parts,
        state: &Arc<AppState>,
    ) -> Result<Self, Self::Rejection> {
        println!("Auth Middleware");
        let version = state.version.clone();
        Ok(Auth(format!("张三 {}", version)))
    }
}
